package team.szm.scd.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import team.szm.scd.database.dto.RequestWrapper;
import team.szm.scd.database.dto.Result;
import team.szm.scd.database.vo.DiseaseVO;
import team.szm.scd.service.interfaces.IDiseaseService;
import team.szm.scd.service.interfaces.ILoginService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/disease")
@Slf4j
public class DiseaseController {
    @Resource
    IDiseaseService service;
    @Resource
    ILoginService loginService;

    @PostMapping("/search")
    @ResponseBody
    public Result<List<DiseaseVO>>
    searchDiseaseLike(@RequestBody RequestWrapper<String> nameOrInfo, HttpSession session) {
        if (loginService.noUserAndNoDoctorLogin(session)) {
            return Result.needLogin();
        }
        List<DiseaseVO> res = service.diseaseLikeNameOrLikeInfo(nameOrInfo.value);
        return Result.success(res);
    }

    @PostMapping("/id")
    @ResponseBody
    public Result<DiseaseVO> fromId(@RequestBody RequestWrapper<Integer> id, HttpSession session) {
        if (loginService.noUserAndNoDoctorLogin(session)) {
            return Result.needLogin();
        }
        DiseaseVO res = service.diseaseFromId(id.value);
        return Result.success(res);
    }
}
